﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Entity;
namespace Web.admin.newsClass
{
    public partial class Class : System.Web.UI.Page
    {
        BLL.NewsClass newsclass = new BLL.NewsClass();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ClassListBind();
            }
        }
        /// <summary>
        /// 类别列表绑定
        /// </summary>
        protected void ClassListBind()
        {
            DataTable dt = newsclass.GetNewsClass();
            RpClass.DataSource = dt;
            RpClass.DataBind();
        }
        /// <summary>
        /// 批量删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int j = 0;
            for (int i = 0; i < RpClass.Items.Count; i++)
            {
                string id = ((Label)RpClass.Items[i].FindControl("lb_id")).Text;
                CheckBox cb = (CheckBox)RpClass.Items[i].FindControl("CbChoose");
                if (cb.Checked)
                {
                    int delRows = newsclass.delSingle(id);
                    if (delRows > 0)
                        j += delRows;
                }
            }
            Response.Write("<script>alert('删除成功，共删除" + j + "条数据');window.location.href='List.aspx'; </script>");
            return;
        }
        /// <summary>
        /// 添加栏目
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AddItem(object sender,EventArgs e)
        {
            BoNewsClass model = new BoNewsClass();
            model.NCTitle = txt_ItmeTitle_add.Value;
            if (Rd_add_yes.Checked)
                model.NCIsShow = true;
            else
                model.NCIsShow = false;
            newsclass.Insert(model);
            Response.Write("<script>alert('添加成功')</script>");
            ClassListBind();
        }
        /// <summary>
        /// 修改栏目
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void EditItem(object sender, EventArgs e)
        {
            BoNewsClass model = new BoNewsClass();
            model.NCTitle = txt_ItmeTitle_edit.Value;
            if (Rd_edit_yes.Checked)
                model.NCIsShow = true;
            else
                model.NCIsShow = false;
            model.NCId = itemId.Value;
            newsclass.UpdateRow(model);
            Response.Write("<script>alert('修改成功')</script>");
            ClassListBind();
        }
    }
}